<?php
$smarty->configLoad($lang . '/querybuilder.module.php');
$language = parse_ini_file($lang . '/breadcrumb.module.php', true);
$breadcrumb = $language['querybuilder'];

			$sql = 'SHOW TABLES FROM '.DB_GAME.'';
			$dbh = $connection->query($sql);
			$select = '';
			while($result = $dbh->fetch()) {
				 $select .= '<option value="'.DB_GAME.'.'. $result[0] . '">'.DB_GAME.'.'. $result[0] . '</option>';
			}
			$sql = 'SHOW TABLES FROM '.DB_LOGIN.'';
			$dbh = $connection->query($sql);
			while($result = $dbh->fetch()) {
				 $select .= '<option value="'.DB_LOGIN.'.'. $result[0] . '">'.DB_LOGIN.'.'. $result[0] . '</option>';
			}
			$smarty->assign('select', $select);
if(isset($_POST['submit'])) {
		
		$q = $connection->prepare("DESCRIBE ".$_POST['from']);
		$q->execute();
		$table_fields = $q->fetchAll(PDO::FETCH_COLUMN);
		$field = '';
		foreach($table_fields as $fields) {
			$field .= '<th><h3>'.$fields.'</h3></th>' ;
		}
		$smarty->assign('field', $field);
	$i = 1;

	$sql = ''.$_POST['query'].' '.$_POST['from'].'';
	$dbh = $connection->prepare($sql);
	$dbh->execute();
	$q = $dbh->fetchAll(PDO::FETCH_ASSOC);
	$value = '';
	foreach($q as $pieces) {
		$value .= '<tr>';
		foreach ($pieces as $piece) {
			$value .= '<td>'.$piece.'</td>';
		}
		$value .= '</tr>';
	}
	$smarty->assign('value', $value);
}
$template = 'querybuilder/index.tpl';
?>
